<template>
  <div>
    <el-form label-width="120px" :model="formData">
      <el-form-item label="机床设备型号">
        <el-select v-model="formData.DeviceModel" placeholder="机床设备型号">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="机床设备号">
        <el-select v-model="formData.DeviceIDs" placeholder="机床设备号">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="工序编号">
        <el-input v-model="formData.tyOPpe" />
      </el-form-item>
      <el-form-item label="加工时间预设">
        <el-input v-model="formData.ProcessTime" />
      </el-form-item>
      <el-form-item label="上料时间和预设">
        <el-input v-model="formData.TransportTime" />
      </el-form-item>
      <!-- <el-form-item label="托盘类型">
        <el-input v-model="formData.type" />
      </el-form-item> -->

      <el-form-item :label-width="0" prop="list">
        <vab-form-table
          v-model="form.list"
          drag
          :row-template="formData.ActionList"
          style="width: 100%"
        >
          <el-table-column align="center" label="动作" prop="ActionOrParam">
            <template #default="{ row }">
              <el-select v-model="row.ActionOrParam" placeholder="动作">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            label="执行设备类型"
            prop="RegisterAddress"
          >
            <template #default="{ row }">
              <el-select
                v-model="row.RegisterAddress"
                placeholder="执行设备类型"
              >
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </template>
          </el-table-column>
          <el-table-column align="center" label="参数" prop="ReadOrWrite">
            <template #default="{ row }">
              <el-select v-model="row.ReadOrWrite" placeholder="参数">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </template>
          </el-table-column>
          <el-table-column align="center" label="值" prop="ValueType">
            <template #default="{ row }">
              <el-select v-model="row.ValueType" placeholder="值">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </template>
          </el-table-column>
        </vab-form-table>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import VabFormTable from '@/extra/VabFormTable'

  export default {
    components: { VabFormTable },
    name: '',
    props: {
      nodeData: {
        type: Object,
        default: () => {},
      },
      lf: {
        type: Object || String,
        default: () => {},
      },
    },
    data() {
      return {
        form: {
          name: '',
          region: '',
          date1: '',
          date2: '',
          delivery: false,
          type: [],
          resource: '',
          desc: '',
        },
      }
    },
    mounted() {
      const { properties } = this.$props.nodeData
      if (properties) {
        this.$data.form = Object.assign({}, this.$data.form, properties)
      }
    },
    methods: {
      onSubmit() {
        console.log('submit!')
        const { id } = this.$props.nodeData
        this.$props.lf.setProperties(id, this.$data.form)
        this.$emit('onClose')
      },
    },
  }
</script>
<style scoped></style>
